import JSEncrypt from 'jsencrypt/bin/jsencrypt.min';

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
	'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDa13ErxPEmj06dNAkeiQPkazot\n' +
	'CEKGH/22NdbzZOdWElYcbR1p/m7R8u+0A7LI7IjwOXPC1NE7tF8aPmLdLEm2aGdS\n' +
	'sW/x+Jsv1jx7F3NM1mke8+5UsduL8QKtzR6eWnrjfCZjMQEVldkGcOrrheiEzYyn\n' +
	'q4abVXe16tyoaQ/ddQIDAQAB';

const privateKey =
	'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANrXcSvE8SaPTp00\n' +
	'CR6JA+RrOi0IQoYf/bY11vNk51YSVhxtHWn+btHy77QDssjsiPA5c8LU0Tu0Xxo+\n' +
	'Yt0sSbZoZ1Kxb/H4my/WPHsXc0zWaR7z7lSx24vxAq3NHp5aeuN8JmMxARWV2QZw\n' +
	'6uuF6ITNjKerhptVd7Xq3KhpD911AgMBAAECgYASRoWj8xl0b+lPxYWxcB3MGIxO\n' +
	'MG9lxgwpCEwAHYAYNwXL7+zR6jaU/+W2scxfbSlubk3VinJCuyhqB6W39LffBUaN\n' +
	'HiV10kz7XF9UTC7iI+K/Kftu2hHCJ5ftdh5cVBXK/NvtWLf05w7UO+99kxEp+VQP\n' +
	'IucrYn4jqn1a7qvDYQJBAOy+1lgoe3KavUNv4+JT8CNqdCFkjSaViK6eVuFcxMXs\n' +
	'zBmsK4xnsriPVK7PzRT5IE8aZ9kDoQIGsBEcX6zd78kCQQDso9YryWfY5Xli0ovp\n' +
	'JrzJN97xScyGhUn3gE73jYjTXkintWDSVLzz2JQdJKMdsA6jfZgKuJGQyS+7TK7k\n' +
	'A85NAkEArESRI8URTutaHOAmKmJ5ssubhVDthM36j1WYUpR2eq88NNIbPieW3MUv\n' +
	'EaUTzdcZs3W7ayZA2oCTTWAgHmHAQQJAeCF8OmJWe7+S7d4g9M2bjTL11Nw4HhpQ\n' +
	'QHs8m2OYkGUO0US80EoAWnIaTukofYvBArJhmx+zliLsPlNhfZOJCQJAA7HQLM+o\n' +
	'OQUGaqn/m59ADd5uK4wHD+Iy37aTwrt7kRXFOOrygnDGYf/UQUG96Y+XvMvNmDRT\n' +
	'QYIsiHADHZTejA==';

// 加密
export function encrypt(txt) {
	const encryptor = new JSEncrypt();
	encryptor.setPublicKey(publicKey); // 设置公钥
	const res = encryptor.encrypt(txt); // 对数据进行加密
	return res;
}

// 解密
export function decrypt(txt) {
	const encryptor = new JSEncrypt();
	encryptor.setPrivateKey(privateKey); // 设置私钥
	const res = encryptor.decrypt(txt); // 对数据进行解密
	return res;
}